package com.tdx.blog_nowcoder.service;

import com.tdx.blog_nowcoder.dao.MessageMapper;
import com.tdx.blog_nowcoder.entity.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageService {
    @Autowired
    private MessageMapper messageMapper;

    public List<Message> selectConversationsByUserId(int userId, int offset, int limit){
        return messageMapper.selectConversationsByUserId(userId,offset,limit);
    }
    public int selectConversationCount(int userId){
        return messageMapper.selectConversationCount(userId);
    }

    public int findMessageCount(String conversationId){
        return messageMapper.findMessageCount(conversationId);
    }
    public int findMessageUnReadCount(int userId,String conversationId){
        return messageMapper.findMessageUnReadCount(userId,conversationId);
    }

    public List<Message> findLettersByConversation(String conversationId, int offset, int limit){
        return messageMapper.findLettersByConversation(conversationId,offset,limit);
    }

    public int findLetterCountByConversation(String conversationId){
        return messageMapper.findLetterCountByConversation(conversationId);
    }

    public int readMessage(List<Integer> ids){
        return messageMapper.updateMessageStatus(ids,1);
    }

    public int addMessage(Message message){
        return messageMapper.addMessage(message);
    }


    public Message findLatestNotice(int userId,String topic){
        //查找用户最新的通知消息， topic={comment,like,follow}三大类
        return messageMapper.findLatestNotice(userId,topic);
    }

    public int findNoticesCount(int userId,String topic){
        return messageMapper.findNoticesCount(userId,topic);
    }

    public int findNoticesUnreadCount(int userId,String topic){
        return messageMapper.findNoticesUnreadCount(userId,topic);
    }

    public List<Message> findNoticesList(int userId,String topic,int offset,int limit){
        return messageMapper.findNoticesList(userId,topic,offset,limit);
    }
}
